package com.googlecode.dgwt.client.dojo.data.base;

import java.util.Collection;
import java.util.List;

import com.googlecode.dgwt.client.dojo.data.model.TableColumn;
import com.googlecode.dgwt.client.dojo.data.model.TableModel;


/**
 * @author      Wellington Tadeu dos Santos
 * @since       DGWT v0.01
 */
public abstract class MatrixStoreBase<Item,Model extends TableModel<List<Item>,Column>,Column extends TableColumn<List<Item>,?>> extends TableStoreBase<List<Item>,Model,Column> implements TableStore<List<Item>> {


    public MatrixStoreBase() {
        super();
    }
    

    public MatrixStoreBase(Collection<? extends List<Item>> items) {
        super(items);
    }
    

    public MatrixStoreBase(int initialCapacity) {
        super(initialCapacity);
    }

    
    @Override
    public Object getValue(List<Item> item, int fieldIndex) {
        return fieldIndex < item.size() ? item.get(fieldIndex) : null;
    }

    
    @Override
    @SuppressWarnings("unchecked")
    public boolean setValue(List<Item> item, int fieldIndex, Object value) {
        if (fieldIndex >= 0 && !isReadOnly()) {
            while (item.size() <= fieldIndex) {
                item.add(null);
            }
            item.set(fieldIndex, (Item) value);
        }
        return false;
    }


}
